package com.thinkin.test;

import java.util.List;

import org.json.JSONObject;

import com.taobao.api.DefaultTaobaoClient;
import com.taobao.api.TaobaoClient;
import com.taobao.api.domain.TradeMonitor;
import com.taobao.api.request.FenxiaoTrademonitorGetRequest;
import com.taobao.api.response.FenxiaoTrademonitorGetResponse;
import com.thinkin.util.ExtendDate;

/**
 * taobao.fenxiao.trademonitor.get 查询经销商品监控 仅限 供应商 调用此接口查询经销商品监控信息
 * 
 * @author Administrator
 * 
 */
public class Trademonitor {
	protected static String url = "http://gw.api.tbsandbox.com/router/rest";// 沙箱环境调用地址

	protected static String appkey = "1021734704";
	protected static String appSecret = "sandboxdad0e025ae5e3ca709c652f6b";

	// 经销商
	protected static String sessionkey = "6100207aafa8bf41383f358b6b07bcf7f8fd75fb40a0cd02054718370";// sandbox_b_23
																										// 供应商

	public static void main(String[] args) throws Exception {
		// TODO Auto-generated method stub
		TaobaoClient client = new DefaultTaobaoClient(url, appkey, appSecret);
		FenxiaoTrademonitorGetRequest req = new FenxiaoTrademonitorGetRequest();
		req.setStartCreated(ExtendDate.getTimestamp("2014-03-25 01:01:01"));
		req.setEndCreated(ExtendDate.getTimestamp("2014-04-16 01:01:01"));
		req.setPageNo(1L);
		req.setPageSize(50L);
		// req.setProductId(1226L);
		req.setDistributorNick("sandbox_c_8");
		req.setFields("trade_monitors.item_title");
		FenxiaoTrademonitorGetResponse response = client.execute(req,
				sessionkey);
		JSONObject jObj2;
		jObj2 = new JSONObject(response.getBody());

		System.out.println("jObj2:" + jObj2.toString());
		List<TradeMonitor> tradeMonitors = response.getTradeMonitors();

		for (int i = 0; tradeMonitors != null && tradeMonitors.size() > 0
				&& i < tradeMonitors.size(); i++) {
			TradeMonitor tradeMonitor = tradeMonitors.get(i);

			System.out.println(tradeMonitor.getProductId().toString());
		}

	}
}
